<?php
/**
 * Created by PhpStorm.
 * User: huynguyen
 * Date: 9/26/14
 * Time: 7:23 PM
 */

namespace Common\Models\Videos;
use Phalcon\Mvc\Model\Validator\Numericality as NumericalityValidator;
use Phalcon\Mvc\Model\Validator\StringLength as StringLengthValidator;

class VideoFile extends \Phalcon\Mvc\Model
{
    protected $id;

    protected $name;

    protected $source_server;

    protected $link_source_server;

    protected $quanlity;

    protected $quanlity_description;

    protected $file_path;

    protected $file_extension;

    protected $protocol;

    protected $agent;

    protected $status;

    public function getSource()
    {
        return 'video_files';
    }

    public function initialize()
    {
        $this->setSource('video_files');

        $this->hasMany('id' , 'Common\Models\VideoFileLink' , 'video_file_id' , array(
            'alias' => 'videoFileLink'
        ));
    }

    public function validation()
    {

        $this->validate(new NumericalityValidator(array(
            'field' => 'quanlity'
        )));

        $this->validate(new StringLengthValidator(array(
            'field' => 'quanlity_description',
            'min'  => 0 ,
            'max'  => 50 ,
            'messageMaximum' => 'We don\'t like really long names',
            'messageMinimum' => 'We want more than just their initials'
        )));

        return $this->validationHasFailed() != true;
    }

    public function beforeDelete()
    {
        $videoFileLink = VideoFileLink::find(array(
            "video_file_id = " . $this->id
        ));
        if($videoFileLink)
        {
            $videoFileLink->delete();
        }
    }

    /**
     * @param mixed $agent
     */
    public function setAgent($agent)
    {
        $this->agent = $agent;
    }

    /**
     * @return mixed
     */
    public function getAgent()
    {
        return $this->agent;
    }

    /**
     * @param mixed $file_extension
     */
    public function setFileExtension($file_extension)
    {
        $this->file_extension = $file_extension;
    }

    /**
     * @return mixed
     */
    public function getFileExtension()
    {
        return $this->file_extension;
    }

    /**
     * @param mixed $file_path
     */
    public function setFilePath($file_path)
    {
        $this->file_path = $file_path;
    }

    /**
     * @return mixed
     */
    public function getFilePath()
    {
        return $this->file_path;
    }

    /**
     * @param mixed $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }


    /**
     * @param mixed $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * @return mixed
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param mixed $quanlity
     */
    public function setQuanlity($quanlity)
    {
        $this->quanlity = $quanlity;
    }

    /**
     * @return mixed
     */
    public function getQuanlity()
    {
        return $this->quanlity;
    }

    /**
     * @param mixed $quanlity_description
     */
    public function setQuanlityDescription($quanlity_description)
    {
        $this->quanlity_description = $quanlity_description;
    }

    /**
     * @return mixed
     */
    public function getQuanlityDescription()
    {
        return $this->quanlity_description;
    }

    /**
     * @param mixed $status
     */
    public function setStatus($status)
    {
        $this->status = $status;
    }

    /**
     * @return mixed
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * @param mixed $protocol
     */
    public function setProtocol($protocol)
    {
        $this->protocol = $protocol;
    }

    /**
     * @return mixed
     */
    public function getProtocol()
    {
        return $this->protocol;
    }

    /**
     * @param mixed $link_source_server
     */
    public function setLinkSourceServer($link_source_server)
    {
        $this->link_source_server = $link_source_server;
    }

    /**
     * @return mixed
     */
    public function getLinkSourceServer()
    {
        return $this->link_source_server;
    }

    /**
     * @param mixed $source_server
     */
    public function setSourceServer($source_server)
    {
        $this->source_server = $source_server;
    }

    /**
     * @return mixed
     */
    public function getSourceServer()
    {
        return $this->source_server;
    }


} 